package logic_setting_role

import (
	v1 "Sailor/app/Sailor-console-server/api/api_setting_role/v1"
	"Sailor/app/Sailor-console-server/internal/dao"
	"Sailor/app/Sailor-console-server/internal/model/entity"
	"context"
	"github.com/gogf/gf/v2/errors/gerror"
	"github.com/gogf/gf/v2/frame/g"
)

func (s *sSettingRole) LogicSettingRoleList(ctx context.Context, req *v1.SettingRoleListReq) (res *v1.SettingRoleListRes, err error) {

	var roles []entity.SysRole
	var total int
	err = dao.SysRole.Ctx(ctx).Page(req.Page, req.PageSize).OrderAsc(dao.SysRole.Columns().RoleSort).ScanAndCount(&roles, &total, true)
	if err != nil {
		g.Log().Error(ctx, err)
		return nil, gerror.New("查询失败")
	}
	return &v1.SettingRoleListRes{
		Page:     req.Page,
		PageSize: req.PageSize,
		Rows:     roles,
		Total:    total,
	}, nil
}
